home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12451 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Is this a C BUG??? (A string issue)
  5. Date: 1 Apr 96 02:11:56 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.828324716@rscernix>
  8. References: <4jknpf$9k3@abel.cc.sunysb.edu>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4jknpf$9k3@abel.cc.sunysb.edu> ghauser@ic.sunysb.edu (George Hauser) writes:
  13.  
  14. >I am reading the whole line in one shot using fgets(). I need to pad with 
  15. >blank spaces those records that are < 194, until the string is set to 194.
  16. >
  17. >Sometimes my records are already filled with 194 and sometimes not.
  18. >
  19. >When I get the string of a line that contains 195 chars (data + eoln) it
  20. >returns a line of 193 and then the next line returns 2 characters.... 
  21.  
  22. This is correct.
  23.  
  24. >This is WRONG fgets should return 194 characters... 
  25.  
  26. Before making a complete fool of yourself, read the description of the
  27. function fgets in your C book.  You'll see, then, who is WRONG :-)
  28.  
  29. >If someone sees something wrong with the code, I'd appreciate the advice.
  30. >But I think this is some obscure messed up hidden character.
  31. >
  32. >Here's the buggy code.
  33. >-----------------
  34. >
  35. >#define linemax 194    /* The predifined lenght of the record */
  36. >
  37. >void main(int argc, char *argv[])
  38.  
  39. You haven't read the FAQ, have you?
  40.  
  41. >{
  42. > FILE *sourcefp, *destfp;    /*Source and destination pointers */
  43. > char line[linemax + 1];    /* The lenght of the line plus NULL terminator */
  44. > long int  records;        /* Number of records that can be passed to ext */
  45. >
  46. > records = 0;
  47. > while(fgets(line,linemax,sourcefp) != NULL)
  48.                    ^^^^^^^
  49. This should be linemax + 1.
  50.  
  51. Dan
  52. --
  53. Dan Pop
  54. CERN, CN Division
  55. Email: danpop@mail.cern.ch 
  56. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  57.